package com.atguigu.dailyservice.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration // 配置类
@EnableSwagger2 // 开启 swagger2 的自动配置
@EnableKnife4j
public class swaggerConfig {

	@Bean
	public Docket docket() {
		// 创建一个 swagger 的 bean 实例
		return new Docket(DocumentationType.SWAGGER_2)
				// 配置基本信息
				.apiInfo(apiInfo())
				.select()
				//配置swagger扫描接口层所在的包
				.apis(RequestHandlerSelectors.basePackage("com.atguigu.dailyservice.controller"))
				.paths(PathSelectors.any())
				.build()
				;
	}

	// 基本信息设置
	private ApiInfo apiInfo() {
		return new ApiInfoBuilder()
				.title("谷粒学院-接口文档") // 标题
				.description("众里寻他千百度，慕然回首那人却在灯火阑珊处=》浮生若梦") // 描述
				.termsOfServiceUrl("https://www.baidu.com") // 跳转连接
				.version("1.0") // 版本
				.build();
	}

}
